package com.kede.pay;

import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
import com.kede.pay.config.WxPayConfig;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.transferbatch.TransferBatchService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import javax.annotation.Resource;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/5/4 10:16
 ***/
@SpringBootApplication(exclude = DynamicDataSourceAutoConfiguration.class)
@MapperScan("com.kede.pay.mapper")
public class PayApplication {

    public static void main(String[] args) {
        SpringApplication.run(PayApplication.class,args);
    }

    @Resource
    private WxPayConfig wxPayConfig;


    /**
     * 自动更新微信支付平台证书
     * @return
     */
    @Bean
    public RSAAutoCertificateConfig autoCertificateConfig(){
        RSAAutoCertificateConfig config =
                new RSAAutoCertificateConfig.Builder()
                        .merchantId(wxPayConfig.getMchId())
                        .privateKeyFromPath(wxPayConfig.getPrivateKeyPath())
                        .merchantSerialNumber(wxPayConfig.getMchSerialNo())
                        .apiV3Key(wxPayConfig.getApiV3Key())
                        .build();
        return config;
    }

}
